package com.huahua.bigdata.sparksql;

import org.apache.spark.sql.Dataset;
import org.apache.spark.sql.Row;
import org.apache.spark.sql.SparkSession;

import java.util.Properties;

public class SparkSQL07_Source_MySQL {
    public static void main(String[] args) {
        final SparkSession sparkSession = SparkSession
                .builder()
                .master("local[*]")
                .appName("SparkSQL")
                .getOrCreate();

        Properties properties = new Properties();
        properties.setProperty("user", "root");
        properties.setProperty("password", "huahua123");

        Dataset<Row> city = sparkSession.read()
                .jdbc("jdbc:mysql://localhost:3306/world?useSSL=false&serverTimezone=UTC&useUnicode=true&characterEncoding=UTF-8&allowPublicKeyRetrieval=true", "city", properties);

        city.write()
                .jdbc("jdbc:mysql://localhost:3306/world?useSSL=false&serverTimezone=UTC&useUnicode=true&characterEncoding=UTF-8&allowPublicKeyRetrieval=true", "city_test", properties);

        sparkSession.close();
    }
}
